package com.swpu.zdl.controller;

import com.swpu.zdl.pojo.XuanKe;
import com.swpu.zdl.service.XuanKeService;
import com.swpu.zdl.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/xuanke")
public class XuanKeController {
    @Autowired
    private XuanKeService xuanKeService;
    // 添加选课
    @PostMapping("/addXuanKe")
    public Result addXuanKe(@RequestBody XuanKe xuanKe){
        Boolean b = xuanKeService.addXuanKe(xuanKe);
        if (!b){
            return new Result(500, "添加选课失败");
        }
        return new Result(200, "添加选课成功");
    }
    // 删除选课
    @DeleteMapping("/deleteXuanKe/{keXuHao}")
    public Result deleteXuanKe(@PathVariable String keXuHao){
        Boolean b = xuanKeService.deleteXuanKe(keXuHao);
        if (!b){
            return new Result(500, "删除选课失败");
        }
        return new Result(200, "删除选课成功");
    }
    // 修改选课
    @PutMapping("/updateXuanKe/{keXuHao}")
    public Result updataXuanKe(@RequestBody XuanKe xuanKe, @PathVariable String keXuHao){
        Boolean b = xuanKeService.updateXuanKe(keXuHao, xuanKe);
        if (!b){
            return new Result(500, "修改选课失败");
        }
        return new Result(200, "修改选课成功");
    }

    // 获取所有选课信息
    @GetMapping("/getAll")
    public Result getAll(){
        List<XuanKe> xuanKes = xuanKeService.getAll();
        return  new Result(200, "所有选课信息", xuanKes);
    }

    // 获取选课和其对应的课程信息
    @GetMapping("/getAllMsg")
    public Result getAllMsg(){
        List<XuanKe> xuanKes = xuanKeService.getAllMsg();
        return  new Result(200, "所有选课及其所属课程信息", xuanKes);
    }
    // 查看当前选课的学生
    @GetMapping("/getMsgWithStudent")
    public Result getMsgWithStudent(String keXuHao){
        XuanKe xuanKe = xuanKeService.getMsgWithStudent(keXuHao);
        return new Result(200, "查看当前选课的学生", xuanKe);
    }


}
